package com.ruitu.health_2.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health_2.mvp.model.SearchModel;
import com.ruitu.health_2.ui.activity.SearchActivity;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.home.SearchData;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class SearchPresenter {

    public static class SearchListP extends BasePresenter<SearchActivity, SearchModel.SearchListM> {
        public Disposable reqSearch(String name) {
            return m.reqSearch(name).subscribe(new Consumer<BaseResult2<SearchData>>() {
                @Override
                public void accept(BaseResult2<SearchData> result) throws Exception {
                    v.hideProgress();
                    if (result.isSuccess()) {
                        v.onReqComplete(1, true, result.getData());
                    } else {
                        ToastUtils.showShortSafe(result.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }
}
